using System;
using System.Collections.Generic;
using System.Text;

using NHibernate;
using Zwms.Data.BusinessObjects;
using Zwms.Data.Base;
using Zwms.Data.CommonObject;
using NHibernate.Criterion;
using System.Reflection;

namespace Zwms.Data.ManagerObjects
{
    public partial interface IWhLocationManager : IManagerBase<Zwms.Data.BusinessObjects.WhLocation, string>
    {
        // Get Methods
        WhLocation GetById(System.String locationCode, System.String warehouseCode);
    }

    partial class WhLocationManager : ManagerBase<Zwms.Data.BusinessObjects.WhLocation, string>, IWhLocationManager
    {
        #region Constructors

        public WhLocationManager()
            : base()
        {
        }
        public WhLocationManager(INHibernateSession session)
            : base(session)
        {
        }

        #endregion

        #region Get Methods

        //public override WhLocation GetById(string id)
        //{
        //    string[] keys = id.Split('^');

        //    if (keys.Length != 2)
        //        throw new Exception("Invalid Id for WhLocationManager.GetById");

        //    return GetById(keys[0], keys[1]);
        //}

        public WhLocation GetById(System.String locationCode, System.String warehouseCode)
        {
            ICriteria criteria = Session.GetISession().CreateCriteria(typeof(WhLocation));

            criteria.Add(NHibernate.Criterion.Expression.Eq("LocationCode", locationCode));
            criteria.Add(NHibernate.Criterion.Expression.Eq("WarehouseCode", warehouseCode));

            WhLocation result = (WhLocation)criteria.UniqueResult();

            if (result == null)
                throw new NHibernate.ObjectDeletedException("", null, null);

            return result;
        }
        #endregion
    }
}